package cn.hl.hm.logic.driver;

import cn.hl.hm.logic.service.IDriverService;
import cn.hl.hm.util.token.TokenUtil;
import cn.hl.hm.vo.DriverDetailVo;
import cn.hl.hm.vo.DriverInfoVo;
import cn.hl.hm.vo.VehicleVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.SQLDataException;
import java.util.List;

/**
 * @description: 司机和车辆逻辑处理
 * @Author: xianghan
 * @Date: 2017/10/27 14:51
 **/
@Service
public class DriverInfoLogic {
    private static final Logger logger = LoggerFactory.getLogger(DriverInfoLogic.class);
    @Autowired
    IDriverService driverService;

    public DriverInfoVo getDriverInfo(String driverToken, String deviceToken) throws Exception {
        Integer driverId = TokenUtil.getTokenBean(driverToken).getId();
        return driverService.getDriverInfo(driverId);
    }

    public DriverDetailVo getDriverDetail(String driverToken, String deviceToken) throws Exception {
        Integer driverId = TokenUtil.getTokenBean(driverToken).getId();
        return driverService.getDriverDetail(driverId,null);
    }

    public List<VehicleVo> getVehicleList(String driverToken) throws Exception{
        Integer driverId = TokenUtil.getTokenBean(driverToken).getId();
        return driverService.getVehicleList(driverId);
    }

    public Boolean addVehicle(String driverToken, String plateNumber, Integer vehicleTpyeId, Integer vehicleLengthId,
                               String transportLicense, String drivingLicensePic, String
                                      drivingLicenseGuaPic) throws SQLDataException {
        Integer driverId = TokenUtil.getTokenBean(driverToken).getId();
        return driverService.addVehicle(driverId, plateNumber, vehicleTpyeId,vehicleLengthId,
                transportLicense, drivingLicensePic, drivingLicenseGuaPic,0);
    }

    public Boolean updateVehicle(String driverToken, String plateNumber, Integer vehicleTpyeId, Integer vehicleLengthId,
                                 String transportLicense, String drivingLicensePic, String drivingLicenseGuaPic,
                                 Integer status, String assessorUsername, String driverUnpassReason) {
        Integer driverId = TokenUtil.getTokenBean(driverToken).getId();
        return driverService.updateVehicle(driverId, plateNumber, vehicleTpyeId, vehicleLengthId,
                transportLicense, drivingLicensePic, drivingLicenseGuaPic, status,assessorUsername,driverUnpassReason);
    }

    public Boolean deleteVehicle(String driverToken, Integer vehicleId){
        Integer driverId = TokenUtil.getTokenBean(driverToken).getId();
        return driverService.deleteVehicle(driverId, vehicleId);
    }
}
